﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using IndyMosaic.Core.Extensions;
using IndyMosaic.Core.Email;
using System.Net.Mail;

namespace IndyMosaic.Models.Web
{
    public class PrayerRequest
    {
        public string Name { get; set; }
        public string PhoneNumber { get; set; }
        public string EmailAddress { get; set; }
        public string Details { get; set; }
        public PrayerRequestConfidentiality Confidentiality { get; set; }

        public void Send()
        {
            StringBuilder body = new StringBuilder();
            body.Append("<html><head></head><body>");
            body.Append("<div><H1>Mosaic Church Prayer Request</h1></div>");
            string fieldValue = "<div><div>{0}: {1}</div></div>";
            body.AppendFormat(fieldValue, "Name", Name);
            body.AppendFormat(fieldValue, "Phone Number", PhoneNumber);
            body.AppendFormat(fieldValue, "Email Address", EmailAddress);
            body.AppendFormat(fieldValue, "Details", "<p>"+ Details +"</p>");
            body.AppendFormat(fieldValue, "Confidentiality", Confidentiality.GetDescription());
            body.Append("</body></html>");

            MailAddress toAddress = null;

            switch (Confidentiality)
            {
                case PrayerRequestConfidentiality.Confidential:
                    toAddress = EmailUtility.PrayerRequestAddressConfidential;
                    break;
                case PrayerRequestConfidentiality.Leaders:
                    toAddress = EmailUtility.PrayerRequestAddressLeaders;
                    break;
                case PrayerRequestConfidentiality.Community:
                    toAddress = EmailUtility.PrayerRequestAddressCommunity;
                    break;
                default:
                    toAddress = EmailUtility.PrayerRequestAddressCommunity;
                    break;
            }


            EmailUtility.SendEmail(EmailUtility.NotificationsAddress, toAddress, "Mosaic Church Prayer Request", body.ToString());
        }
    }

    public enum PrayerRequestConfidentiality
    {
        [Description("kept confidential")]
        Confidential,
        [Description("shared with the leaders of Mosaic to join with you in prayer")]
        Leaders,
        [Description("shared with others in the Mosaic community to join with you in prayer")]
        Community
    }
}
